package db;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import javax.persistence.AttributeConverter;
import java.util.Map;

public class ObjectJsonConverter implements AttributeConverter<Map<String,String>,String> {
    @Override
    public String convertToDatabaseColumn(Map<String, String> attribute) {
        return JSON.toJSONString(attribute);
    }

    @Override
    public Map<String, String> convertToEntityAttribute(String dbData) {
        return JSON.parseObject(dbData,new TypeReference<Map<String,String>>(){});
    }
}
